package com.lancoo.edu.platform.operation.backupRestore.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lancoo.edu.platform.operation.backupRestore.domain.vo.BackupRecordeProductVo;
import com.lancoo.edu.platform.operation.backupRestore.service.bo.BrBackupRecordeBoService;
import com.lancoo.edu.platform.operation.commons.annotation.CheckToken;
import com.lancoo.edu.platform.operation.commons.controller.base.BaseResultController;
import com.lancoo.edu.platform.operation.commons.dto.BaseResult;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author lzh
 * @Date 2024/4/3 16:03
 * @description 备份记录控制器
 */
@RestController
@RequestMapping("/api/backupRestore/backup/recorde")
@AllArgsConstructor
@Validated
public class BrBackupRecordeController extends BaseResultController {

    private final BrBackupRecordeBoService brBackupRecordeBoService;

    /**
     * 获取备份记录列表
     *
     * @param pageNum     当前页
     * @param pageSize    页大小
     * @param eduId       教育局ID
     * @param keyword     关键字
     * @return 备份记录列表
     */
    @CheckToken
    @GetMapping("/list")
    public BaseResult getBackupRecordeList(@NotNull(message = "当前页") @RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                           @NotNull(message = "页大小") @RequestParam(defaultValue = "10", required = false) Integer pageSize,
                                           @NotBlank(message = "教育局ID不能为空") String eduId, String keyword) {
        IPage<BackupRecordeProductVo> productVoPage = brBackupRecordeBoService.getBackupRecordeList(eduId, keyword, pageNum, pageSize);
        return success(productVoPage.getTotal(), productVoPage.getRecords());
    }

    /**
     * 获取指定系统备份记录列表
     *
     * @param pageSize 页大小
     * @param eduId    教育局ID
     * @param sysId    系统ID
     * @return 备份记录列表
     */
    @CheckToken
    @GetMapping("/bySys/info")
    public BaseResult getBackupRecordeSysInfo(@NotNull(message = "页大小") @RequestParam(defaultValue = "100", required = false) Integer pageSize,
                                              @NotBlank(message = "教育局ID不能为空") String eduId, @NotBlank(message = "系统ID不能为空") String sysId) {
        return success(brBackupRecordeBoService.getBackupRecordeSysInfo(pageSize, eduId, sysId));
    }

    /**
     * 获取还原全部备份时选择的备份列表
     *
     * @param eduId    教育局ID
     * @return 备份记录列表
     */
    @CheckToken
    @GetMapping("/byRestoreAll")
    public BaseResult getBackupRecordByRestoreAll(@Valid @NotBlank(message = "教育局ID不能为空") String eduId) {
        return success(brBackupRecordeBoService.getBackupRecordByRestoreAll(eduId));
    }
}
